package com.herohead;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class SendGmail {


	public static String toEmail;
	public static String fromEmail;
	private static String username;
	private static String password;
	private static String subject;
	private static String body;


	public static boolean sendEMail(){
		Properties props = new Properties();
		props.put("mail.smtp.host", "smtp.gmail.com");
		props.put("mail.smtp.socketFactory.port", "465");
		props.put("mail.smtp.socketFactory.class",
				"javax.net.ssl.SSLSocketFactory");
		props.put("mail.smtp.auth", "true");
		props.put("mail.smtp.port", "465");

		Session session = Session.getDefaultInstance(props,
				new javax.mail.Authenticator() {
			@Override
			protected PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication(username,password);
			}
		});

		try {

			Message message = new MimeMessage(session);
			message.setFrom(new InternetAddress(fromEmail));
			message.setRecipients(Message.RecipientType.TO,
					InternetAddress.parse(toEmail));
			message.setSubject(subject);
			message.setText(body);

			Transport.send(message);
			return true;
			//System.out.println("Done");

		} catch (MessagingException e) {
			return false;
			//throw new RuntimeException(e);

		}
	}
	public String getToEmail(){
		return toEmail;
	}

	public void setBody(String bdy) {
		body = bdy;
	}

	public void setFromemail(String StrFromEmail) {
		fromEmail = StrFromEmail;
	}
	public void setSubject (String sject){
		subject = sject;
	}

	public void setToemail(String StrtoEmail) {
		toEmail = StrtoEmail;
	}

	public void setUserNamePassword (String uname, String pword){
		username = uname;
		password = pword;
	}
}
